package com.scw.dao.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.scw.dao.LinkInfoDao;
import com.scw.model.LinkInfo;
import com.scw.model.Tip;

public class LinkInfoDaoImpl extends HibernateDaoSupport implements LinkInfoDao {
	@Autowired
	private LinkInfo linkInfo;

	public void delete(Long id) {
		getHibernateTemplate().delete(
				getHibernateTemplate().get(LinkInfo.class, id));
	}

	public void delete(LinkInfo linkInfo) {
		getHibernateTemplate().delete(linkInfo);
	}

	@SuppressWarnings("unchecked")
	public List<LinkInfo> findAll() {
		String sql="from LinkInfo";
		return (List<LinkInfo>) this.getHibernateTemplate().find(sql);
	}

	public LinkInfo get(Long id) {
		LinkInfo linkInfo=(LinkInfo) getHibernateTemplate().get(LinkInfo.class, id);
		return linkInfo;
	}

	public LinkInfo save(LinkInfo linkInfo) {
		getHibernateTemplate().save(linkInfo);
		return linkInfo;

	}

	public void update(LinkInfo linkInfo) {
		getHibernateTemplate().update(linkInfo);
	}

	@SuppressWarnings("unchecked")
	public List<LinkInfo> findByUserId(Long userId) {
		List<LinkInfo> linkInfoList = (List<LinkInfo>) getHibernateTemplate()
				.find(" from com.scw.model.LinkInfo where sysuser.id = ?",
						new Object[] { userId });
		return linkInfoList;
	}

	public LinkInfo getLinkInfo() {
		return linkInfo;
	}

	public void setLinkInfo(LinkInfo linkInfo) {
		this.linkInfo = linkInfo;
	}

	public List<LinkInfo> listByTip(Tip tip) {
		String HQL="FROM LinkInfo where tip_id=?";
		if(tip.getId()==null)
			return null;
		return getHibernateTemplate().find(HQL,new Object[]{tip.getId()});
	}
}
